import echarts from 'echarts';
// 引入柱状图
import 'echarts/lib/chart/bar';
// 引入提示框和标题组件
import 'echarts/lib/component/tooltip';
import 'echarts/lib/component/title';
import storageApi from '../../../core/storage/storage';

/*eslint-disable */
function consStatsNumController($rootScope, $scope, homeStatsService) {
  'ngInject';

  const date = new Date();
  // 处理日期
  this.dateToStr = (date, format) => {
    var date_arr = {
      "M+": date.getMonth() + 1,
      "d+": date.getDate(),
      "h+": date.getHours(),
      "m+": date.getMinutes(),
      "s+": date.getSeconds(),
      "q+": Math.floor((date.getMonth() + 3) / 3),
      "S+": date.getMilliseconds()
    };
    if (/(y+)/i.test(format)) {
      format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    for (var k in date_arr) {
      if (new RegExp("(" + k + ")").test(format)) {
        format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? date_arr[k] : ("00" + date_arr[k]).substr(("" + date_arr[k]).length));
      }
    }
    return format;
  }

  // 获取资料总量
  this.getDocumentNum = () => {
    this.params = {
      orgId: $scope.orgId,
      yearMonth: this.dateToStr(date, 'yyyy-MM'),
    };
    homeStatsService
      .queryDocumentNum(this.params)
      .then((res) => {
        if (res.success) {
          this.statsDocumentNum = res.data;
          this.statsDocumentNum.name = '资料总量';
        }
      });
  };

  this.getDocumentNum();

  this.init = () => {
    homeStatsService
      .getSafeActivityStatsNum({ orgId: $scope.orgId })
      .then((res) => {
        if (res.success) {
          this.statsNum = res.data;
        }
      });
  };

  this.init();
}

export default consStatsNumController;
